mod utils;

use wasm_bindgen::prelude::*;

// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen]
extern {
  fn alert(s: &str);
}

#[wasm_bindgen]
pub fn greet() {
  alert("Hello, demo!");
}


#[wasm_bindgen]
pub fn fib(v: u32) -> u32 { // rust递归实现斐波那契数列第n项
  if v == 1 {
    return 1;
  }
  if v == 2 {
    return 2;
  }
  return fib(v - 1) + fib(v - 2);
  // match v {
  //   1 => 1,
  //   2 => 1,
  //   _ => fib(v - 1) + fib(v - 2)
  // }
}
